package client.handler;

import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import qq.message.DataPackage;
import qq.panel.gui.simple.PanelSimpleGUI;

public class ReceiveHandler {

	public void handleReceiveList(DataPackage data,PanelSimpleGUI psg){
		
		System.out.println("get a list message"); 
		System.out.println(data.getMessageData());
		String nameString=data.getMessageData();
		String [] names=(nameString.substring(1, data.getMessageData().length()-1)).split(",");
		TreeSet<String> nameSet=new TreeSet<String>();
		for(int i=0;i<names.length;i++){
			nameSet.add(names[i]);
		}
		psg.resetList(nameSet);
	}
	
	public void handleReceiveMessage(DataPackage data,PanelSimpleGUI psg){
		StringBuilder str=new StringBuilder();
		str.append(data.getFromName()+"  ");
		str.append(new Date(data.getTime()).toString());
		str.append("\n  ");
		str.append(data.getMessageData());
		str.append("\n");
		psg.getChatTa().append(str.toString());
		psg.getChatTa().updateUI();
	}
	
	public void handleReceiveShake(DataPackage data,PanelSimpleGUI psg){
		psg.shake();
		
	}

	public void handleReceiveLogout(DataPackage receive, PanelSimpleGUI psg) {
		// TODO Auto-generated method stub
		System.exit(0);
	}

}
